{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First of all we need to install [ranx](https://github.com/AmenRa/ranx)\n",
    "\n",
    "Mind that the first time you run any ranx' functions they may take a while as they must be compiled first.\n",
    "Try running the code again to see actual usage speed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install ranx"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interpolated Precision-Recall Curve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ranx import Qrels, Run, plot\n",
    "\n",
    "qrels = Qrels.from_ir_datasets(\"msmarco-passage/trec-dl-2020/judged\")\n",
    "\n",
    "runs = [\n",
    "    Run.from_ranxhub(\"msmarco-passage/trec-dl-2020/ranxhub/ance\"),\n",
    "    Run.from_ranxhub(\"msmarco-passage/trec-dl-2020/ranxhub/bm25-pyserini\"),\n",
    "    Run.from_ranxhub(\"msmarco-passage/trec-dl-2020/ranxhub/distilbert-kd\"),\n",
    "    Run.from_ranxhub(\"msmarco-passage/trec-dl-2020/ranxhub/distilbert-kd-tasb\"),\n",
    "    Run.from_ranxhub(\"msmarco-passage/trec-dl-2020/ranxhub/unicoil\"),\n",
    "]\n",
    "\n",
    "plot(qrels, runs, graph=\"iprec_at_recall\", figsize=(8, 5))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The plot can be customized by passing `seaborn_kwargs={...}`.  \n",
    "More information about [`seaborn`](https://seaborn.pydata.org/index.html)'s lineplot can be found [here](https://seaborn.pydata.org/generated/seaborn.lineplot.html)."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also ask for raw values in the form of a [pandas](https://pandas.pydata.org)' [DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) to use with your favorite plot library!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = plot(qrels, runs, graph=\"iprec_at_recall\", return_graph=False)\n",
    "df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ranx",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
